﻿namespace MINERP.COM {
	#region

	using System;
	using System.Linq;
	using System.Runtime.InteropServices;
	using System.Text;


	#endregion

	public class IniFile {
		public static IniFile Ini;
		public static string AppPath;
		public static string ReportPath;
		public static string ReportFilePath;
		public static string VoiPath;
		private static bool _autoOrderOnceOrder;
		private static int[] _zgProCatId;
		public string Path;
		static IniFile() {
			string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");
			Ini = new IniFile(path);
			//			OrilRootPath = Ini.IniReadValue("Order", "OrilRootPath", "E:\\wh_order");
			AppPath = AppDomain.CurrentDomain.BaseDirectory;
			ReportPath = AppPath + "Reports";
			ReportFilePath = AppPath + "报表文件";
			VoiPath = AppPath + "Voi";
			//			PhotoWuCha = Convert.ToInt32(Ini.IniReadValue("Order", "PhotoWuCha", "10"));
			//			OrderLocalPath = Ini.IniReadValue("Order", "OrderLocalPath", "E:\\Temp");
			//			OrderByCtmFolder = Ini.IniReadValue("Order", "OrderBYCtmFolder", "1") == "1";
		
		}
		public IniFile(string inipath) {
			Path = inipath;
		}
        public static int BarCodePixWidth
        {
            get { return Convert.ToInt32(Ini.IniReadValue("BP", "BarCodePixWidth", "25")); }
            set { Ini.IniWriteValue("BP", "BarCodePixWidth", value.ToString()); }
        }
		public static float MaxWaste {
			get { return Convert.ToSingle(Ini.IniReadValue("AUTOPB", "MaxWaste", "20")); }
			set { Ini.IniWriteValue("AUTOPB", "MaxWaste", value.ToString()); }
		}
		public static float ClearWaste {
			get { return Convert.ToSingle(Ini.IniReadValue("AUTOPB", "ClearWaste", "30")); }
			set { Ini.IniWriteValue("AUTOPB", "ClearWaste", value.ToString()); }
		}
		public static float OCCPB {
			get { return Convert.ToSingle(Ini.IniReadValue("AUTOPB", "OCCPB", "70")); }
			set { Ini.IniWriteValue("AUTOPB", "OCCPB", value.ToString()); }
		}
		public static float OCCClearPB {
			get { return Convert.ToSingle(Ini.IniReadValue("AUTOPB", "OCCClearPB", "50")); }
			set { Ini.IniWriteValue("AUTOPB", "OCCClearPB", value.ToString()); }
		}
		public static int CombineGridType {
			get { return Convert.ToInt32(Ini.IniReadValue("CombinedProcessManager", "CombineGridType", "2")); }
			set { Ini.IniWriteValue("CombinedProcessManager", "CombineGridType", value.ToString()); }
		}
		
		public const string LocalDisk = "W:";
		////声明读写INI文件的API函数 
		[DllImport("kernel32")]
		private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
		[DllImport("kernel32")]
		private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
		//写INI文件
		public void IniWriteValue(string Section, string Key, string Value) {
			WritePrivateProfileString(Section, Key, Value, Path);
		}

		//读取INI文件指定
		public string IniReadValue(string Section, string Key, string defVal ) {
			StringBuilder temp = new StringBuilder(1000);
            if (string.IsNullOrEmpty(defVal))
            {
                defVal = "";
            }
			int i = GetPrivateProfileString(Section, Key, "", temp, 1000, Path);
			if (temp.Length == 0) {
				IniWriteValue(Section, Key, defVal);
				return defVal;
			}
			return temp.ToString();
		}
        public string IniReadValue(string Section, string Key)
        {
            string defVal = "";
            StringBuilder temp = new StringBuilder(1000);
            if (string.IsNullOrEmpty(defVal))
            {
                defVal = "";
            }
            int i = GetPrivateProfileString(Section, Key, "", temp, 1000, Path);
            if (temp.Length == 0)
            {
                IniWriteValue(Section, Key, defVal);
                return defVal;
            }
            return temp.ToString();
        }
	}
}
